#include <string>

using namespace std;

class Solution
{
public:
    string replaceSpaces(string S, int length)
    {
        string ret;
        for (int i = 0; i < length; ++i)
        {
            if (S[i] == ' ')
            {
                ret += "%20";
            }
            else
            {
                ret += S[i];
            }
        }
        return ret;
    }
};